package com.beiding.pojo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Message {

    private static ObjectMapper objectMapper = new ObjectMapper();


    public static Message create(String receiver, Object payload) {

        Message message = new Message();

        message.setReceiver(receiver);

        try {
            message.setPayload(objectMapper.writeValueAsString(payload));
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        return message;

    }

    //负载必须是字符串类型
    private String payload;

    //接受者
    private String receiver;


}
